package com.adream.scalpel.app.client.ui;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Scalpel implements EntryPoint {
    private ScalpelMenuTree menuTree;
    private HorizontalSplitPanel horizontalSplitPanel;

    private FlexTable flexTable;
    private TabPanel screenTabPanel;

    public void onModuleLoad() {
        RootPanel rootPanel = RootPanel.get();

        flexTable = new FlexTable();
        rootPanel.add(flexTable, 0, 0);
        flexTable.setSize("100%", "100%");

        final TopPanel topPanel = new TopPanel();
        flexTable.setWidget(0, 0, topPanel);
        flexTable.getCellFormatter().setHeight(0, 0, "20px");

        horizontalSplitPanel = new HorizontalSplitPanel();
        horizontalSplitPanel.setSplitPosition("20%");
        flexTable.setWidget(1, 0, horizontalSplitPanel);
        horizontalSplitPanel.setSize("100%", "100%");
        flexTable.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);

        menuTree = new ScalpelMenuTree(this);
        horizontalSplitPanel.setLeftWidget(menuTree);
        menuTree.setSize("100%", "100%");

        screenTabPanel = new TabPanel();
        horizontalSplitPanel.setRightWidget(screenTabPanel);
        screenTabPanel.setSize("100%", "100%");
    }

    public void addScreen(Composite screen, String screenTitle) {
        screenTabPanel.add(screen, screenTitle);
        screenTabPanel.selectTab(screenTabPanel.getWidgetIndex(screen));
    }
}
